<template>
	<div class="exercises-wrong-title" v-loading.fullscreen.lock="loading"
		element-loading-text="拼命加载中">
		
		<ul>
			<template v-for="(item, index) of errorQuestion"> 
				<li class="exercises-wrong-ls" :key="index"  v-if="item.error_count > 0">
					<router-link v-if="item.error_count != 0" :to="{path: '/exercises/wrong-exercises', query:{id: item.id, name: item.name}}">{{item.name}}</router-link>
					<span v-else>{{item.name}}</span>
					<div>
						<span>最后更新时间：   {{item.update_time}}</span>
						<router-link v-if="item.error_count != 0" :to="{path: '/exercises/wrong-exercises', query:{id: item.id, name: item.name}}">错题数<i>{{item.error_count}}</i></router-link>
						<span v-else>错题数<i>{{item.error_count}}</i></span>
					</div>
				</li>
			</template>
		</ul>

		<div class="dependent" v-if="placeholder">
			<i class="ipng image_state01"></i>
			<p>还没发现任何相关的内容哦~</p>
		</div>

		<el-pagination class="test-pagination" v-if="question.total > 9"
			@size-change="sizeChange"
			@current-change="currentChange"
			:current-page="question.page"
			:page-sizes="[10, 50, 100, 200, 300, 400]"
			:page-size="question.size"
			layout="total, sizes, prev, pager, next, jumper"
			:total="question.total">
		</el-pagination>
	</div>
</template>

<script>
	export default {
		data(){
			return {
				question: {
					page: 1,
					size: 9,
					total: 0,
				},
				placeholder: false,
				loading:true,
				subjectLsit: [],
				errorQuestion: [],
			}
		},
		created(){
			this.getErrorQuestion()
		},
		methods: {
			getErrorQuestion(){

				let success = (res=>{
					this.errorQuestion = res.data.data;
					this.question.page = res.data.page_index;
					this.question.total = res.data.data_sum;
					this.errorQuestion.length != 0 ? this.placeholder = false : this.placeholder = true;
					this.loading = false
				});

				let params = {
					// grade_id: xxx,
					user_id: this.$g.user_id,
					page_index: this.question.page,
					page_size: this.question.size,
				};

				this.$ajax({
					url: 'api/newtest/get_errorquestion_list',
					method: 'get',
					params: params,
					func: {success: success}
				})
			},
			sizeChange(val) {
				this.question.page = 1
				this.question.page = val;
				this.getErrorQuestion()
			},
			currentChange(val) {
				this.question.page = val;
				this.getErrorQuestion()
			}
		}
	}
</script>